local liaofan = fk.CreateSkill{
  name = "hanqing__liaofan",
}

Fk:loadTranslationTable{
  ["hanqing__liaofan"] = "燎燔",
  [":hanqing__liaofan"] = "每回合结束时，你可以弃置手牌均为明置牌的所有角色的所有手牌，并对这些角色各造成1点火焰伤害。",

  ["#hanqing__liaofan-invoke"] = "燎燔：是否弃置这些角色所有手牌并各造成1点火焰伤害？",
}

local DIY = require "packages/diy_utility/diy_utility"

liaofan:addEffect(fk.TurnEnd, {
  anim_type = "offensive",
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(liaofan.name) and
      table.find(player.room.alive_players, function (p)
        return not p:isKongcheng() and
          table.every(p:getCardIds("h"), function (id)
            return table.contains(DIY.getShownCards(p), id)
          end)
      end)
  end,
  on_cost = function(self, event, target, player, data)
    local room = player.room
    local success, dat = room:askToUseActiveSkill(player, {
      skill_name = "hanqing__liaofan_active",
      prompt = "#hanqing__liaofan-invoke",
      cancelable = true,
    })
    if success and dat then
      local tos = table.filter(room:getAlivePlayers(), function (p)
        return not p:isKongcheng() and
          table.every(p:getCardIds("h"), function (id)
            return table.contains(DIY.getShownCards(p), id)
          end)
      end)
      event:setCostData(self, {tos = tos})
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local tos = event:getCostData(self).tos
    for _, p in ipairs(tos) do
      if not p.dead and not p:isKongcheng() then
        room:throwCard(p:getCardIds("h"), liaofan.name, p, player)
      end
    end
    for _, p in ipairs(tos) do
      if not p.dead then
        room:damage{
          from = player,
          to = p,
          damage = 1,
          damageType = fk.FireDamage,
          skillName = liaofan.name,
        }
      end
    end
  end,
})

return liaofan
